<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车牌" prop="licensenum">
        <el-input
          v-model="queryParams.licensenum"
          placeholder="请输入车牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item label="里程" prop="km">
        <el-input
          v-model="queryParams.km"
          placeholder="请输入里程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="price">
          <el-input
          v-model="queryParams.price"
          placeholder="请输入单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="优惠单价" prop="dinterprice">
        <el-input
          v-model="queryParams.dinterprice"
          placeholder="请输入优惠单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="余量警告" prop="warny">
        <el-select v-model="queryParams.warny" placeholder="余量警告" clearable>
          <el-option
            v-for="dict in dict.type.t_warn"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="gasolineList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="号牌" align="center" prop="licensenum" />
      <el-table-column label="当前里程" align="center" prop="km" />
      <el-table-column label="剩余容积" align="center" prop="revo" />
      <el-table-column label="剩余里程" align="center" prop="rekm" />
      <el-table-column label="预计里程" align="center" prop="plkm" />
      <el-table-column prop="status" label="余量警告" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.t_warn" :value="scope.row.warny"/>
        </template>
      </el-table-column>
      <el-table-column label="剩余百分比" align="center" prop="bfvoy" />
      <el-table-column label="预计加注容积" align="center" prop="plvo" />
      <el-table-column label="预计加注金额" align="center" prop="plfee" />
      <el-table-column label="总里程" align="center" prop="totalkmy" />
      <el-table-column label="总容积" align="center" prop="totalvoy" />
      <el-table-column label="实际单价" align="center" prop="price" />
      <el-table-column label="优惠单价" align="center" prop="dinterprice" />
      <el-table-column label="满箱总金额" align="center" prop="totalfeey" />
      <!-- <el-table-column label="满箱实际支付" align="center" prop="distotalfeey" />
      <el-table-column label="满箱优惠金额" align="center" prop="ntertotalfeey" /> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getInfoGasoline, getGasoline, delGasoline, addGasoline, updateGasoline } from "@/api/ljj/gasoline/gasoline";

export default {
  name: "Gasoline",
  dicts: ['t_full_status', 't_oil_grade', 't_warn'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 加油表格数据
      gasolineList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        licensenum: 0,
        km: 0,
        revo: null,
        rekm: null,
        warny: 0,
        plvo: null,
        plfee: null,
        totalkmy: null,
        totalvoy: null,
        price: 0,
        dinterprice: 0,
        totalfeey: null,
        distotalfeey: null,
        ntertotalfeey: null,
        plkm: null,
      },
       // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 实时详情
    getInfo(){
      this.$router.push('/ljj/task-getInfoV/getInfoV')
    },
    /** 查询加油列表 */
    getList() {
       this.loading = true;
        getInfoGasoline(this.queryParams).then(response => {
        this.gasolineList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        licensenum: 0,
        km: 0,
        revo: null,
        rekm: null,
        warny: null,
        plvo: null,
        plfee: null,
        totalkmy: null,
        totalvoy: null,
        price: 0,
        dinterprice: 0,
        totalfeey: null,
        distotalfeey: null,
        ntertotalfeey: null,
        plkm: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGasoline(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGasoline(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGasoline(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //初始化时间
    createDate() {
      var nowDate = new Date(new Date().getTime()-1000*60*60*24*30);
      var nowDate2 = new Date(new Date().getTime()+1000*60*60*24);
      var startdate = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        day: nowDate.getDate(),
      }
        var endDate = {
        year: nowDate2.getFullYear(),
        month: nowDate2.getMonth() + 1,
        day: nowDate2.getDate(),
      }
      var startdate = startdate.year + '-' + (startdate.month >= 10 ? startdate.month : '0' + startdate.month) + '-' + (startdate.day >= 10 ? startdate.day : '0' + startdate.day);
      var endDate = endDate.year + '-' + (endDate.month >= 10 ? endDate.month : '0' + endDate.month) + '-' + (endDate.day >= 10 ? endDate.day : '0' + endDate.day);
      this.dateRange = [startdate,endDate];
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除加油编号为"' + ids + '"的数据项？').then(function() {
        return delGasoline(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/gasoline/export', {
        ...this.queryParams
      }, `gasoline_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
